package com.devilvan;

import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.context.annotation.Bean;

import javax.servlet.Servlet;

@SpringBootApplication
@MapperScan(basePackages = "com.devilvan.mapper")
@EnableEurekaClient
@EnableDiscoveryClient
// 添加对熔断的支持
// 新版的@EnableHystrix 包含了旧版的 @EnableCircuitBreaker
@EnableHystrix
@EnableCircuitBreaker
public class HystrixProvider8001 {

    public static void main(String[] args) {
        SpringApplication.run(HystrixProvider8001.class, args);
    }

    // 创建一个Servlet 的bean，完善dashboard的监控
    @Bean
    public ServletRegistrationBean hystrixDashboardServlet(){
        ServletRegistrationBean<Servlet> registrationBean =
                new ServletRegistrationBean<>(
                        new HystrixMetricsStreamServlet()
                );
        registrationBean.addUrlMappings("/actuator/hystrix.stream");
        return registrationBean;
    }
}
